package gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class DiagramEditor extends Shell {
	
	private Canvas canvas;
	private Menu menu;
	private MenuItem mntmFile;
	private Menu menu_1;
	private MenuItem mntmEdit;
	private Menu menu_2;
	private MenuItem mntmCut;
	private MenuItem mntmCopy;
	private MenuItem mntmPaste;
	private MenuItem mntmNew;
	private MenuItem mntmOpen;
	private MenuItem mntmSave;
	private MenuItem mntmExit;
	private Group grpFigures;
	private Button btnTestPackageDiagram;
	private Button btnTstClassDiagram;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			DiagramEditor shell = new DiagramEditor(display);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * @param display
	 */
	public DiagramEditor(Display display) {
		super(display, SWT.SHELL_TRIM);
		addControlListener(new ControlAdapter() {
			@Override
			public void controlResized(ControlEvent e) {
			}
		});
		
		setCanvas(new Canvas(this, SWT.NONE));
		getCanvas().setBounds(163, 10, 980, 660);
		
		menu = new Menu(this, SWT.BAR);
		setMenuBar(menu);
		
		mntmFile = new MenuItem(menu, SWT.CASCADE);
		mntmFile.setText("File");
		
		menu_1 = new Menu(mntmFile);
		mntmFile.setMenu(menu_1);
		
		mntmNew = new MenuItem(menu_1, SWT.NONE);
		mntmNew.setText("New");
		
		mntmOpen = new MenuItem(menu_1, SWT.NONE);
		mntmOpen.setText("Open");
		
		mntmSave = new MenuItem(menu_1, SWT.NONE);
		mntmSave.setText("Save");
		
		new MenuItem(menu_1, SWT.SEPARATOR);
		
		mntmExit = new MenuItem(menu_1, SWT.NONE);
		mntmExit.setText("Exit");
		
		mntmEdit = new MenuItem(menu, SWT.CASCADE);
		mntmEdit.setText("Edit");
		
		menu_2 = new Menu(mntmEdit);
		mntmEdit.setMenu(menu_2);
		
		mntmCut = new MenuItem(menu_2, SWT.NONE);
		mntmCut.setText("Cut");
		
		mntmCopy = new MenuItem(menu_2, SWT.NONE);
		mntmCopy.setText("Copy");
		
		mntmPaste = new MenuItem(menu_2, SWT.NONE);
		mntmPaste.setText("Paste");
		
		grpFigures = new Group(this, SWT.NONE);
		grpFigures.setText("Figures");
		grpFigures.setBounds(10, 10, 147, 407);
		
		btnTestPackageDiagram = new Button(this, SWT.NONE);
		btnTestPackageDiagram.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				GUIManager.getDefault().generatePackageDiagram("C:\\rootPkg");
			}
		});
		btnTestPackageDiagram.setBounds(10, 633, 147, 25);
		btnTestPackageDiagram.setText("test package diagram");
		
		btnTstClassDiagram = new Button(this, SWT.NONE);
		btnTstClassDiagram.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				GUIManager.getDefault().generateClassDiagram("C:\\TestClass.java");
			}
		});
		btnTstClassDiagram.setText("test class diagram");
		btnTstClassDiagram.setBounds(10, 602, 147, 25);
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("Diagram Editor - UML Modeler");
		setSize(1169, 738);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

	public void setCanvas(Canvas canvas) {
		this.canvas = canvas;
		Device device = null;
		canvas.setBackground(new Color(device, new RGB(255, 255, 255)));
	}

	public Canvas getCanvas() {
		return canvas;
	}
}
